''' 读取所有的图片到一个txt文件里,好像和exact_img_dir重复了'''


import os
from tqdm import tqdm

img_file_path = r'/home/xys/CppProjects/darknet/large-object/obj/labels/'        #图像路径
txt_save_path = r'/home/xys/CppProjects/darknet/large-object/obj/'                #txt保存路径
prefix_path = r'/home/xys/larger_objet_Projects/obj_det_larger_object/larger_obj_train_data/VOC2007/JPEGImages/'   #图片路径


file_names = os.listdir(img_file_path)
lens = len(file_names)

for file_name in tqdm(file_names[0:int(0.8*lens)]):
    file_name_pos = file_name[-4:]
    if file_name_pos == ".jpg":
        txt_file = open(txt_save_path + "train.txt", 'a')
        txt_file.write(prefix_path + file_name + "\n")
        txt_file.close()

for file_name in tqdm(file_names[0.8*lens:0.9*lens]):
    file_name_pos = file_name[-4:]
    if file_name_pos == ".jpg":
        txt_file = open(txt_save_path + "valid.txt", 'a')
        txt_file.write(prefix_path + file_name + "\n")
        txt_file.close()

for file_name in tqdm(file_names[0.9*lens:lens]):
    file_name_pos = file_name[-4:]
    if file_name_pos == ".jpg":
        txt_file = open(txt_save_path + "test.txt", 'a')
        txt_file.write(prefix_path + file_name + "\n")
        txt_file.close()

for file_name in tqdm(file_names[0:0.9*lens]):
    file_name_pos = file_name[-4:]
    if file_name_pos == ".jpg":
        txt_file = open(txt_save_path + "trainval.txt", 'a')
        txt_file.write(prefix_path + file_name + "\n")
        txt_file.close()